package com.garlic.face.jlf.ui;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.garlic.face.jlf.R;
import com.garlic.face.jlf.base.BaseActivity;
import com.garlic.face.jlf.presenter.PartialPaymentContract;
import com.garlic.face.jlf.presenter.PartialPaymentPresenter;
import com.garlic.face.jlf.transaction.Means;
import com.garlic.face.jlf.transaction.bean.TradeHead;
import com.garlic.face.jlf.utils.ScreenUtils;
import com.garlic.face.jlf.utils.Tools;
/**
 * Created by shiyanqi on 18/9/29.
 */

public class PartialPaymentActivity extends BaseActivity implements PartialPaymentContract.View {
	private static final String TAG = "PartialPaymentActivity";
	private ImageView mShopBrand;
	private Button continuePayBtn;


	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_partial_payment);

		TradeHead tradeHead = Means.getInstance().getRec_Tran();

		mShopBrand = (ImageView) findViewById(R.id.title_img);
		mShopBrand.setImageDrawable(this.getResources().getDrawable(R.mipmap.jlf_logo));

		TextView total_amount = (TextView) findViewById(R.id.total_amount);
		total_amount.setText("¥" + Tools.getFormatNumber(tradeHead.getAmount() + tradeHead.getDisc_amt()));

		TextView price = (TextView) findViewById(R.id.price);
		price.setText("¥" + Tools.getFormatNumber(tradeHead.getAmount()));

		TextView number = (TextView) findViewById(R.id.number);
		double count = tradeHead.getCount();
		String tv = "共" + (int) count + "件商品";
		String textStr = String.format(getResources().getString(R.string.total_goods_number), (int) count);
		SpannableStringBuilder stringBuilder = new SpannableStringBuilder(tv);
		stringBuilder.setSpan(new AbsoluteSizeSpan(ScreenUtils.sp2px(PartialPaymentActivity.this, 20)), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		stringBuilder.setSpan(new ForegroundColorSpan(this.getResources().getColor(R.color.gray_color)), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		stringBuilder.setSpan(new AbsoluteSizeSpan(ScreenUtils.sp2px(PartialPaymentActivity.this, 20)), tv.length() - 3, tv.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		stringBuilder.setSpan(new ForegroundColorSpan(this.getResources().getColor(R.color.gray_color)), tv.length() - 3, tv.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		number.setText(textStr);

		String remain = getIntent().getStringExtra("remain");
		Double partialPay = tradeHead.getAmount() - Double.valueOf(remain);
		TextView card_pay_amount = (TextView) findViewById(R.id.card_pay_amount);
		card_pay_amount.setText("-¥" + Tools.getFormatNumber(partialPay));

		continuePayBtn = findViewById(R.id.continue_pay);
		continuePayBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Means.getInstance().getRec_Tran().setAmount(Double.valueOf(remain));
				finish();
			}
		});

	}


	@Override
	public void toSuccssActivity(String result) {

	}

	@Override
	public void toFailureActivity(String msg) {

	}

	@Override
	public void gotoMain() {

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		if(event.getKeyCode() == KeyEvent.KEYCODE_BACK ) {
			//do something.
			return true;
		}else {
			return super.dispatchKeyEvent(event);
		}
	}

}
